package banco;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Conexao {
	private static Conexao instance = null;
	private String host = "jdbc:mysql://localhost/cheques";
	private boolean status = false;
	private String login = "root";
	private String senha = "1";
	private String driver = "com.mysql.jdbc.Driver";
	private Connection conexao=null ;


	// private Statement statement= null;

	public void setLogin(String login) {
		this.login = login;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public Connection getConexao() throws ClassNotFoundException, SQLException {

		
			if(this.conexao == null || this.conexao.isClosed()){
				Class.forName(this.driver);
				this.conexao = DriverManager.getConnection(host, this.login,this.senha);
				return conexao;
			}
			return conexao;
		

	}

	public void desconectar() throws SQLException {
		if(this.conexao!=null && !this.conexao.isClosed()){
			this.conexao.close();
			}

	}
	private Conexao(){
		
	}

	public static Conexao getInstancia() {
		if (instance == null) {
			instance = new Conexao();
			return instance;

		}

		return instance;

	}

	


}
